package menu;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PanelSetting extends JPanel implements MouseListener{
	private static final long serialVersionUID = 30520100019L;
	private JLabel		labelScreen;
	private JLabel		labelMusic;
	private JLabel		labelEffects;
	public  JComboBox	cmbScreen;
	public  JComboBox	cmbMusic;
	public  JComboBox	cmbEffects;
	private JButton		btnPlay;
	private JButton		btnCancel;
	private Font 		f = new Font("IMPACT", Font.PLAIN, 16);
	private String[]    screenSize = {"640x300","640x480","720x576","800x600","1024x1078","fullscreen"};
	private String[]    onOff = {"ON","OFF"};
	private static PanelSetting panelSetting;
	
	public static PanelSetting getInstance()
	{
		if(panelSetting!=null) return panelSetting;
		return null;		
	}
	
	public PanelSetting(PanelMain panelMain)
	{
		super(true);
		this.setOpaque(false);
		this.setLayout(new GridLayout(6,0,5,5));
		this.setPreferredSize(new Dimension(300, 50));
		this.setBorder(null);
		labelScreen = new JLabel("Screen size:");
		setComponent(labelScreen);
		labelMusic  = new JLabel("Music:");
		setComponent(labelMusic);
		labelEffects = new JLabel("Effects:");
		setComponent(labelEffects);
		
		cmbScreen = new JComboBox(screenSize);
		setComponent(cmbScreen);
		cmbScreen.setBackground(Color.blue.darker());
		cmbMusic = new JComboBox(onOff);
		setComponent(cmbMusic);
		cmbMusic.setBackground(Color.blue.darker());
		cmbEffects = new JComboBox(onOff);
		setComponent(cmbEffects);
		cmbEffects.setBackground(Color.blue.darker());
		
		btnPlay = new JButton("OK");
		setComponent(btnPlay);
		btnPlay.setBorder(null);
		btnPlay.addMouseListener(this);
		
		btnCancel = new JButton("CANCEL");
		setComponent(btnCancel);
		btnCancel.setBorder(null);
		btnCancel.addMouseListener(this);
		
		this.add(labelScreen);
		this.add(cmbScreen);
		this.add(labelMusic);
		this.add(cmbMusic);
		this.add(labelEffects);
		this.add(cmbEffects);
		this.add(btnPlay);
		this.add(btnCancel);
		this.setVisible(false);
		
		PanelSetting.panelSetting=this;
	}

	private void setComponent(JComponent c)
	{
		c.setFont(f);
		c.setBackground(Color.orange);
		c.setOpaque(false);
		c.setAlignmentX(CENTER_ALIGNMENT);
		c.setAlignmentY(CENTER_ALIGNMENT);
		c.setForeground(Color.orange);
		c.setFocusable(true);
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getSource().equals(btnCancel))
		{
			System.out.println("CANCEL");
			this.setVisible(false);
			return;
		}
		else
		{
			System.out.println("OK");
			PanelMain.getInstance();
			PanelMain.settings.playerScreen = cmbScreen.getSelectedIndex();
			PanelMain.settings.playerMusic = cmbMusic.getSelectedIndex();
			PanelMain.settings.playerEffects = cmbEffects.getSelectedIndex();
			PanelMain.settings.updateXML();
			this.setVisible(false);
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
